home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Sample Code / 7Edit 3.1 / Sources / SVAEWindowUtils.c < prev    next >
Encoding:
Text File  |  1995-11-20  |  3.0 KB  |  145 lines  |  [TEXT/CWIE]

  1. // SVAEWindowUtils.c
  2. //
  3. // 7Edit 3.1d1. Original version by Jon Lansdell and Nigel Humphreys.
  4. // 3.1 updates by Greg Sutton.
  5. // ©Apple Computer Inc 1995, all rights reserved.
  6.  
  7. #include "SVAEWindowUtils.h"
  8.  
  9. #include "SVEditWindow.h"        // for DPtrFromWindowPtr()
  10.  
  11.  
  12.  
  13. #include <LowMem.h>
  14.  
  15.  
  16.  
  17.  
  18. WindowPtr WindowNameToWindowPtr(StringPtr nameStr)
  19. /* 
  20.     Returns the WindowPtr of the window with title nameStr
  21.     or nil if there is no matching window.
  22. */
  23.     { 
  24.         WindowPtr theWindow;
  25.         Str255    windTitle;
  26.             
  27.         theWindow =(WindowPtr)LMGetWindowList();
  28.         /* 
  29.             iterate through windows - we use WindowList 'cos we could
  30.             have made the window invisible and  we lose it - so we
  31.             can't set it back to visible!!
  32.         */
  33.         while (theWindow)
  34.             {
  35.                 GetWTitle(theWindow, windTitle);
  36.                 if (EqualString(windTitle,
  37.                                 nameStr,
  38.                                                 false,
  39.                                                 true))     /* ignore case, don't ignore diacriticals */
  40.                     return(theWindow);
  41.               theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  42.             }
  43.         return(theWindow);
  44.     }    /* WindowNameToWindowPtr */
  45.  
  46.     
  47. OSErr    GetDescOfNamedWindow(StringPtr nameStr, AEDesc* result)
  48. {
  49.     WindowToken        theToken;
  50.     OSErr            err = noErr;
  51.     
  52.     theToken.tokenWindow = WindowNameToWindowPtr(nameStr);
  53.     
  54.     if (theToken.tokenWindow)
  55.         err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
  56.     else
  57.         err = errAENoSuchObject;
  58.  
  59.     return(err);
  60. }
  61.  
  62.  
  63. short CountWindows(void)
  64. {
  65.     WindowPtr theWindow;
  66.     short     index;
  67.             
  68.     index = 0;
  69.     theWindow = (WindowPtr)LMGetWindowList();
  70.  
  71.     // iterate through windows
  72.     while (theWindow)
  73.         {
  74.             index++;                    
  75.           theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  76.         }
  77.     
  78.     return(index);
  79. } // CountWindows
  80.  
  81.  
  82. WindowPtr GetWindowPtrOfNthWindow(short index)
  83. /* returns a ptr to the window with the given index
  84.   (front window is 1, behind that is 2, etc.).  if
  85.   there's no window with that index (inc. no windows
  86.   at all), returns nil.
  87. */
  88.   {
  89.       WindowPtr theWindow;
  90.         
  91.         theWindow = (WindowPtr)LMGetWindowList();
  92.     
  93.         /* iterate through windows */
  94.         
  95.         while (theWindow)
  96.             {
  97.                 index --;
  98.                 if (index <= 0) 
  99.                     return(theWindow);
  100.                     
  101.               theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  102.             }
  103.         return(nil);
  104.     }    /* GetWindowPtrOfNthWindow */
  105.     
  106. short    GetNthWindowOfWindowPtr(WindowPtr aWindow)
  107. // Given a WindowPtr this routine tries to find the
  108. // index to that window. If not found it will return
  109. // zero
  110. {
  111.     WindowPtr theWindow;
  112.     short     index;
  113.             
  114.     index = 0;
  115.     theWindow = (WindowPtr)LMGetWindowList();
  116.  
  117.         // iterate through windows
  118.     while (theWindow)
  119.     {
  120.         index++;
  121.         if (theWindow == aWindow)
  122.             return(index);
  123.                         
  124.         theWindow = (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  125.     }
  126.     
  127.     return(0);
  128. } // GetNthWindowOfWindowPtr
  129.  
  130.  
  131. OSErr    GetDescOfNthWindow(short index, AEDesc* result)
  132. {
  133.     WindowToken        theToken;
  134.     OSErr            err = noErr;
  135.     
  136.     theToken.tokenWindow = GetWindowPtrOfNthWindow(index);
  137.     
  138.     if (theToken.tokenWindow)
  139.         err = AECreateDesc(typeMyWndw, (Ptr)&theToken, sizeof(theToken), result);
  140.     else
  141.         err = errAEIllegalIndex;
  142.  
  143.     return(err);
  144. }
  145.